import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/growthcyclePropertites/list',
  save = '/growthcyclePropertites/add',
  edit = '/growthcyclePropertites/edit',
  deleteOne = '/growthcyclePropertites/delete',
  batchDelete = '/growthcyclePropertites/deleteBatch',
  importExcel = '/growthcyclePropertites/importExcel',
  exportXls = '/growthcyclePropertites/exportXls',
  sort = '/growthcyclePropertites/sort',
}

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.post({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({ url: Api.batchDelete, params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 排序
 * @param params
 */
export const sort = (params, handleSuccess) => {
  return defHttp.put({ url: Api.sort, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
